package cn.tedu.icop.common.interceptor;
import cn.tedu.icop.common.context.PageContext;
import cn.tedu.icop.common.pojo.PageData;
import cn.tedu.icop.common.utils.StringUtils;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class PageInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        String pageNumStr=request.getParameter("pageNum");
        String pageSizeStr=request.getParameter("pageSize");
        int pageNum = StringUtils.isEmpty(pageNumStr)?1:Integer.parseInt(pageNumStr);
        int pageSize = StringUtils.isEmpty(pageSizeStr)?3:Integer.parseInt(pageSizeStr);
        //存起来，存哪里？
        System.out.println("======AAAAAAAAA=======");
        PageContext.setPageData(new PageData(pageNum,pageSize));
        return true;//放行
    }
    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
        //将存起来的数据移除
        PageContext.removePageData();//防止内存泄漏
    }
}
